package com.djhu.newscollector.crawel.imp.cl;

import com.djhu.newscollector.core.Holder.JobHolder;
import com.djhu.newscollector.core.dispatch.JobDispatcher;
import com.djhu.newscollector.crawel.core.PageProcess;
import com.djhu.newscollector.crawel.core.ProcessMatcher;
import com.djhu.newscollector.crawel.core.Url;
import com.djhu.newscollector.crawel.imp.wangyi.DefaultPageProcess;
import com.djhu.newscollector.crawel.imp.worker.MongoService;
import com.djhu.newscollector.crawel.imp.worker.WangyiNewsWorker;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * Created by zw on 2018/2/12.
 */
public class ClProcessMatcher implements ProcessMatcher{

    private static Logger logger = LogManager.getLogger(ClProcessMatcher.class.getName());


    private JobHolder jobHolder;

    private JobDispatcher jobDispatcher;

    private MongoService mongoService;


    @Override
    public PageProcess match(Url link) {
        String url = link.getUrl();
        if (url.contains("htm_data")){
            logger.info("url is " + url + "match process" + "ImgPageProcessor");
            ImagePageProcess process = new ImagePageProcess();
            return process;
        }else if (url.contains("page")){
            logger.info(url + " type is IndexPageProcess");
            IndexPageProcess indexPageProcess = new IndexPageProcess();
            indexPageProcess.setJobDispatcher(jobDispatcher);
            indexPageProcess.setJobHolder(jobHolder);
            return  indexPageProcess;
        }
        return new DefaultPageProcess();
    }

    public JobHolder getJobHolder() {
        return jobHolder;
    }

    public void setJobHolder(JobHolder jobHolder) {
        this.jobHolder = jobHolder;
    }

    public JobDispatcher getJobDispatcher() {
        return jobDispatcher;
    }

    public void setJobDispatcher(JobDispatcher jobDispatcher) {
        this.jobDispatcher = jobDispatcher;
    }
}